/*
1.定时器ros::Rate()
2.定时器ros::createTimer()
*/
#include "ros/ros.h"

void callback(const ros::TimerEvent &timerEvent)
{
    ROS_INFO("timer implement. called once in 2 secs.");
    ROS_INFO("%f.", timerEvent.current_real.toSec());
}

int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");
    //初始化节点
    ros::init(argc, argv, "ros_timer_test");
    //创建句柄
    ros::NodeHandle nh;
    // rate 发布频率
    // ros::Rate rate(1);
    // while (true)
    // {
    //     ROS_INFO("test rate timer once in one secend");
    //     rate.sleep();
    // }

    //使用定时器timer
    ros::Timer timer = nh.createTimer(ros::Duration(2), //间隔时间
                                      callback,         //回调函数
                                      false,            //只调用一次
                                      true);            //自动启动
    ros::spin(); //必须加上这句话，否则程序直接退出了
    return 0;
}
